package cn.liwq.study.demo.netty.lab;

/**
 * @author lweiqiang
 * @date 2021/5/12
 */
public class MainTest {
    public static void main(String[] args) {
        System.out.println(toBits(Integer.toBinaryString(0)));
        System.out.println(toBits(Integer.toBinaryString(2)));
        System.out.println(toBits(Integer.toBinaryString(4)));
        System.out.println();
        System.out.println(toBits(Integer.toBinaryString(7)));
        System.out.println();
        System.out.println(toBits(Integer.toBinaryString(1 & 8 - 1)));
        System.out.println(toBits(Integer.toBinaryString(3 & 8 - 1)));
        System.out.println(toBits(Integer.toBinaryString(5 & 8 - 1)));
    }

    private static String toBits(String s) {
        StringBuilder prefix = new StringBuilder();
        for (int i = 0; prefix.length() + s.length() < 8; i++) {
            prefix.append("0");
        }
        return prefix + s;
    }
}
